package cn.wolfcode.restful.controller;

import cn.wolfcode.restful.domian.Employee;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;
import javax.websocket.server.PathParam;
import java.util.Arrays;

//@Controller
@RestController     //  @ResponseBody+@Controller
@RequestMapping("employees")
public class EmployeeController {

    //列表
    /*@RequestMapping(value = "/employees", method = RequestMethod.GET)
    @ResponseBody*/

    @GetMapping
    public Object list() {
        return Arrays.asList(new Employee(1L, "张杰", 35), new Employee(2L, "马云", 56));
    }

    //保存
    /*@RequestMapping(value = "/employees", method = RequestMethod.POST)
    @ResponseBody*/

    @PostMapping
    public Object save() {
        return Arrays.asList(new Employee(1L, "张杰", 35), new Employee(2L, "马化腾", 50));
    }

   /* //更新
    @RequestMapping(value = "/employees", method = RequestMethod.PUT)
    @ResponseBody*/

   @PutMapping
    public Object update() {
        return Arrays.asList(new Employee(1L, "张杰", 35));
    }

    //删除
    /*@RequestMapping(value = "/employees/{id}", method = RequestMethod.DELETE)
    @ResponseBody*/

    @DeleteMapping("{id}")
    public Object delete( Long id) {
        return "删除"+id;
    }
    /*//单个查找  散装参数      参数路径要与@PathVariable属性相同
    @RequestMapping(value = "/employees/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Object selectOne(@PathVariable("id") Long id) {
        return id;
    }*/

    /*//经测试,路径与参数路径冲突时,路径优先
    @RequestMapping(value = "/employees/5", method = RequestMethod.GET)
    @ResponseBody
    public Object test() {
        return "ok";
    }*/

    //单个查找  对象参数    对象参数不要贴@PathVariable
   /* @RequestMapping(value = "/employees/{id}/{name}/{age}", method = RequestMethod.GET)
    @ResponseBody*/

    @GetMapping(value = "{id}/{name}/{age}",headers = "content-type=text/xml")
    public Object get(Employee employee) {
        return employee;
    }
}
